package com.efuture.chapterthree

/* @Description:KT语言的replace操作
 * @Auther: zhaoshanshan
 * @Date: 2022/03/06/10:44 上午
 */
fun main() {
    val  sourcePwd = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    println("原始密码是:$sourcePwd")
    //使用replace对密码进行加密
    val newPwd = sourcePwd.replace(Regex("[BFHYM]")){
        when(it.value){
            "B"->"1"
            "F"->"2"
            "H"->"3"
            "M"->"4"
            "Y"->"5"
            else->it.value
        }
    }
    println("加密后的密码为:$newPwd")
    //继续使用replace对密码进行解密
   val delaWithPwd = newPwd.replace(Regex("[12345]")){
       when(it.value){
           "1"->"B"
           "2"->"F"
           "3"->"H"
           "4"->"M"
           "5"->"Y"
           else->it.value
       }
   }
   println("解密后的密码为:$delaWithPwd")

}